//
//  TabBarManager.swift
//  AnShiPai
//
//  Created by 马瑜 on 2017/7/7.
//  Copyright © 2017年 马瑜. All rights reserved.
//

import UIKit

enum TabBarManager {
    
    static func undertakeTabbarWithNavigationStyle() -> ESTabBarController {
        let tabBarController = ESTabBarController()
        let v1 = UIStoryboard.mainStoryboard?.instantiateViewController(withIdentifier: "UndertakeViewController") as! UndertakeViewController
        let v2 = UIStoryboard.mainStoryboard?.instantiateViewController(withIdentifier: "UnderMineViewController") as! UnderMineViewController
        v1.tabBarItem = ESTabBarItem.init(DefaultBasicContentView(), title: "接单", image: #imageLiteral(resourceName: "T-Home-default"), selectedImage: #imageLiteral(resourceName: "T-Home-select"))
        v2.tabBarItem = ESTabBarItem.init(DefaultBasicContentView(), title: "我的", image: #imageLiteral(resourceName: "T-Mine-defalut"), selectedImage: #imageLiteral(resourceName: "T-Mine-Select"))
        
        let n1 = DefaultNavigationController.init(rootViewController: v1)
        let n2 = DefaultNavigationController.init(rootViewController: v2)
        
        v1.title = "接单"
        v2.title = "我的"
        
        tabBarController.viewControllers = [n1, n2]
        
        return tabBarController
    }
    
    static func transferTabbarWithNavigationStyle() -> ESTabBarController {
        let tabBarController = ESTabBarController()
        let v1 = UIStoryboard.mainStoryboard?.instantiateViewController(withIdentifier: "TransferViewController") as! TransferViewController
        let v2 = UIStoryboard.mainStoryboard?.instantiateViewController(withIdentifier: "TranMineViewController") as! TranMineViewController
        v1.tabBarItem = ESTabBarItem.init(DefaultBasicContentView(), title: "甩单", image: #imageLiteral(resourceName: "T-Home-default"), selectedImage: #imageLiteral(resourceName: "T-Home-select"))
        v2.tabBarItem = ESTabBarItem.init(DefaultBasicContentView(), title: "我的", image: #imageLiteral(resourceName: "T-Mine-defalut"), selectedImage: #imageLiteral(resourceName: "T-Mine-Select"))
        
        let n1 = DefaultNavigationController.init(rootViewController: v1)
        let n2 = DefaultNavigationController.init(rootViewController: v2)
        
        v1.title = "甩单"
        v2.title = "我的"
        
        tabBarController.viewControllers = [n1, n2]
        
        return tabBarController
    }
}

class DefaultBasicContentView: ESTabBarItemContentView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        textColor = UIColor.init(white: 175.0 / 255.0, alpha: 1.0)
        highlightTextColor = GlobalColor!
        iconColor = UIColor.init(white: 175.0 / 255.0, alpha: 1.0)
        highlightIconColor = GlobalColor!
    }
    
    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}

class DefaultNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        let appearance = UIBarButtonItem.appearance()
        appearance.setBackButtonTitlePositionAdjustment(UIOffset.init(horizontal: 0.0, vertical: -60), for: .default)
        self.navigationBar.isTranslucent = true
        self.navigationBar.barTintColor = GlobalColor
//        self.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.init(red: 38/255.0, green: 38/255.0, blue: 38/255.0, alpha: 1.0), NSFontAttributeName: UIFont.systemFont(ofSize: 18.0)]
        self.navigationBar.tintColor = UIColor.white
    }
    
}





